using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UserGUI : MonoBehaviour
{
    public int mode;
    public int score;
    public int round;
    public string gameMessage;
    private IUserAction action;
    public GUIStyle bigStyle, smallStyle, buttonStyle;//自定义字体格式
    public Font titleFont, buttonFont;
    private int menu_width = Screen.width / 5, menu_height = Screen.width / 10;//主菜单每一个按键的宽度和高度
    // Start is called before the first frame update
    void Start()
    {
        gameMessage = "";
        action = SSDirector.getInstance().currentSceneController as IUserAction;

        //pixelStyle
        //pixelFont = Font.Instantiate(Resources.Load("Fonts/ThaleahFat", typeof(Font))) as Font;
        //if (pixelFont == null) Debug.Log("null");
        //pixelFont.fontSize = 50;
        //pixelFont = Arial;
        
        //大字体初始化
        bigStyle = new GUIStyle();
        bigStyle.normal.textColor = new Color(137f / 255f, 56f / 255f, 144f / 229f);
        bigStyle.normal.background = null;
        bigStyle.fontSize = 50;
        titleFont = Resources.Load<Font>("Font/title");
        bigStyle.font = titleFont;
        bigStyle.alignment=TextAnchor.MiddleCenter;

        //小字体初始化
        smallStyle = new GUIStyle();
        smallStyle.normal.textColor = Color.black;
        smallStyle.normal.background = null;
        smallStyle.fontSize = 25;
        buttonFont = Resources.Load<Font>("Font/button");
        smallStyle.font = buttonFont;
        smallStyle.alignment=TextAnchor.MiddleCenter;

        // button样式设置
        buttonStyle = new GUIStyle();
        buttonStyle.fontSize = 45;
        buttonStyle.font = buttonFont;
        buttonStyle.alignment=TextAnchor.MiddleCenter;
        // buttonStyle.normal.background = MakeTex(2, 2, new Color(232f / 255f, 215f / 255f, 195f / 229f)); 
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnGUI() {
        //GUI.skin.button.font = pixelFont;
        switch(mode) {
            case 0:
                mainMenu();
                break;
            case 1:
                GameStart();
                break;
            
        }       
    }

    void mainMenu() {
        GUI.Label(new Rect(Screen.width / 2 - menu_width * 0.5f, Screen.height * 0.1f, menu_width, menu_height), "Catch The Butterfly!", bigStyle);
        if (GUI.Button(new Rect(Screen.width / 2 - menu_width * 0.5f, Screen.height * 3 / 7, menu_width, menu_height), "Start", buttonStyle)) {
            mode = 1;
            // Debug.Log("Mode changed to: " + mode);
        }
        
    }
    void GameStart() {
        GUI.Label(new Rect(450, 120, 50, 200), gameMessage, bigStyle);
        GUI.Label(new Rect(10,5,100,50), "Score: " + score, smallStyle);
        GUI.Label(new Rect(560,5,100,50), "Round: " + round, smallStyle);
    }

    // 生成一个简单的 2x2 像素的纹理，用来作为按钮背景
    Texture2D MakeTex(int width, int height, Color color)
    {
        Color[] pix = new Color[width * height];
        for (int i = 0; i < pix.Length; i++) pix[i] = color;
        Texture2D texture = new Texture2D(width, height);
        texture.SetPixels(pix);
        texture.Apply();
        return texture;
    }
}
